package com.ckm.service;

import com.ckm.annotation.MongoDS;
import com.ckm.context.DynamicMongoContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
public class TestTService implements TService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Autowired
    private T2Service t2Service;

    @Override
    @MongoDS("test1")
    public void test1() {
//        ((TService)AopContext.currentProxy()).test2();
//        log.info(Thread.currentThread().getName());
//        for (int i = 0; i < 10; i++) {
//            new Thread(new Runnable() {
//                @Override
//                public void run() {
//                    test2();
//                }
//            }).start();
//        }
//        test2();
        t2Service.test();
        log.info(mongoTemplate.getDb().getName());
    }

    @MongoDS("test2")
    @Override
    public void test2(){
        log.info(mongoTemplate.getDb().getName());
    }

    @Override
    @MongoDS("test5")
    public void test5() {
        log.info(mongoTemplate.getDb().getName());
    }

}
